#import "headViewCell.h"

@interface headViewCell ()

@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation headViewCell


-(void)setImage:(id)image {

    _image = image;
    
    [self setupUI];
}





- (void)setupUI {
    
    
    [self.contentView addSubview:self.imageView];
    
    
    self.imageView.frame = self.frame;
    
    

        if ([self.image isKindOfClass:[NSURL class]]) {
    
            NSURL *imgUrl = self.image;
            [self.imageView sd_setImageWithURL:imgUrl placeholderImage:self.placeholder];
    
            self.imageView.image = [self imageWithImageSimple:self.imageView.image scaledToSize:self.bounds.size];
        } else if ([self.image isKindOfClass:[NSString class]]) {
    
            self.imageView.image = [UIImage imageNamed:self.image];
        }
    
}


#pragma mark - 压缩图片的方法
// 压缩图片
- (UIImage *)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
    UIGraphicsBeginImageContext(newSize);
    
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}



#pragma mark - 懒加载控件

- (UIImageView *)imageView {
    
    if (_imageView == nil) {
        _imageView = [[UIImageView alloc] init];
        
        
    }
    return _imageView;
}



@end
